from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.support.select import Select
from time import  sleep
# 创建浏览器驱动对象
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait

driver = webdriver.Chrome()
# 加载web页面
driver.get("http://121.43.169.97:8848/pageA.html")

# 放大浏览器
driver.maximize_window()
# 1. 导包 Select类 --> from selenium.webdriver.support.select import Select
# 2. 实例化Select类 select = Select(driver.find_element_by_id("selectA"))
# 3. 调用方法：select.select_by_index(index)
# 需求：使用‘注册A.html’页面，完成对城市的下拉框的操作
# # 下标索引 index
# # 1).选择‘广州’
# el = driver.find_element_by_css_selector("#selectA")
# select= Select(el)
# sleep(2)
# select.select_by_index(2)
#
# # 2).暂停2秒，选择‘上海’
# sleep(2)
# select.select_by_index(1)
# # 3).暂停2秒，选择‘北京
# sleep(2)
# select.select_by_index(0)


# #  value
# 1).选择‘广州’
# el = driver.find_element_by_css_selector("#selectA")
# select= Select(el)
# sleep(2)
# select.select_by_value("gz")
#
# # 2).暂停2秒，选择‘上海’
# sleep(2)
# select.select_by_value("sh")
# # 3).暂停2秒，选择‘北京
# sleep(2)
# select.select_by_value("bj")


# #  文本显示
# 1).选择‘广州’
el = driver.find_element_by_css_selector("#selectA")
select= Select(el)
sleep(2)
select.select_by_visible_text("广州")

# 2).暂停2秒，选择‘上海’
sleep(2)
select.select_by_visible_text("上海")
# 3).暂停2秒，选择‘北京
sleep(2)
select.select_by_visible_text("北京")

sleep(3)
driver.quit()